#Include ../../_lib/Cursor.ahk

CoordMode 'Mouse', 'Screen'

Esc:: ExitApp()

#Include debugView.ahk
#Include render.ahk
#Include constants.ahk

mainGui := Gui('+AlwaysOnTop -Caption +Border')
mainGui.BackColor := '656565'
mainGui.Show('h500 w500')
mainGui.GetPos(&x, &y, &w, &h)


dt := DrawTool(mainGui, 0)
dt.Show('x' x + w)


class DrawTool extends Gui {

  __New(parent, dire) {
    super.__New('+AlwaysOnTop +ToolWindow -Caption +Owner' parent.hwnd)
    this.SetFont('s18', 'MaytermOne')
    this.MarginX := 0
    this.MarginY := 0
    r := Render(this, mainGui)

    this.sizeIndicator := this.AddButton('w40 h40  Disabled', '2')
    this.AddButton('xs w40 h40', 'A').OnEvent('Click', (*) => r.RenderLine())
    this.AddButton('xs w40 h40', 'B').OnEvent('Click', (*) => r.RenderRect())
    this.AddButton('xs w40 h40', 'C').OnEvent('Click', (*) => r.RenderRectSolid())
    this.AddButton('xs y+20 w40 h40', 'V').OnEvent('Click', (*) => (r.EndDraw(), this.Destroy()))
    this.AddButton('xs w40 h40', '<').OnEvent('Click', (*) => r.undo())
  }


  Show(opt) {
    super.Show(opt)
  }
}


OnMessage(0x020A, ChangePenW)

ChangePenW(wParam, *) {
  MouseGetPos(, , &hwnd, &ctrl, 2)
  if not ((g := GuiFromHwnd(hwnd)) is Gui)
    return
  _w := Render.penSize
  w := (wParam >> 16 = 120) ? Min(9, _w + 1) : Max(1, _w - 1)
  GuiCtrlFromHwnd(ctrl).Text := w, Render.penSize := w
}